package com.cart.protocol.analyze;

import com.cart.protocol.ProtocolDefine;

/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2020-01-16
       Time     :  10:37
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    关于 门指令回复的解析
 */
public class RockingValveRespAnalyze extends RespAnalyze {

    private static final String TAG = "ROCKING_VALVE";

    public RockingValveRespAnalyze(String rawDeviceInfo) {
        super(rawDeviceInfo);
    }

    protected RockingValveRespAnalyze analyze() {
        //20 0a03 cc 00
        //对门的操作解析
        StringBuilder resultBuilder = new StringBuilder();
        String operator = rawDeviceInfo.substring(length - 4, length - 2);
        if (operator.toUpperCase().equals(ProtocolDefine.OperateCommand.OPEN)) {
            resultBuilder.append("开启");
        } else {
            resultBuilder.append("关闭");
        }
        resultBuilder.append("摇床");
        String commandWordRes = rawDeviceInfo.substring(0, 2);
        if (commandWordRes.equals(ProtocolDefine.CommandWordRes.ACTION_SUCCESS)) {
            resultBuilder.append("成功");
        } else {
            resultBuilder.append("失败");
        }
        report = resultBuilder.toString();
        return this;
    }

    private void readDoorStatus() {
        String doorStatus = rawDeviceInfo.substring(length - 2, length);
        switch (doorStatus.toUpperCase()) {
            case ProtocolDefine.DoorStatus.DOOR_CLOSE:
                System.out.println("电机门关闭");
                report = "电机门关闭";
                break;
            case ProtocolDefine.DoorStatus.DOOR_OPEN_HALF:
                System.out.println("电机门半开半闭状态");
                report = "电机门半开半闭状态";
                break;
            case ProtocolDefine.DoorStatus.DOOR_OPEN_BIGGEST:
                System.out.println("电机门处于开启最大位置");
                report = "电机门处于开启最大位置";
                break;
            default:
                break;
        }
    }
}
